#include "C_Slide.h"


C_Slide::C_Slide(std::string filename, float sec, float startMsec)
{
	m_endTime = sf::seconds(sec);
	m_sprite.loadFromFile(filename);
	m_sprite.setPos(-m_sprite.width() / 2.0f + WINDOW_WIDTH / 2.0f, -m_sprite.height() / 2.0f + WINDOW_HEIGHT / 2.0f);
	m_end = false;

	m_startEf = sf::milliseconds(startMsec);
	m_startEfInc = 255.f / m_startEf.asMilliseconds();
	m_sprite.setColor(255, 255, 255, sf::Uint8(0));

	m_clock.restart();
}


C_Slide::~C_Slide()
{
}

void C_Slide::render()
{
	m_sprite.render();
}

void C_Slide::update()
{
	if (m_endTime <= m_clock.getElapsedTime())
	{
		m_end = true;
	}

	sf::Time nowTime = m_clock.getElapsedTime();
	if (nowTime <= m_startEf)
	{
		int opacity = m_startEfInc * nowTime.asMilliseconds();
		m_sprite.setColor(255, 255, 255, sf::Uint8(opacity));
	}

}

void C_Slide::show()
{
	m_clock.restart();
}

void C_Slide::handleEvent(sf::Event e)
{
	VC_Drawable::handleEvent(e);
	switch (e.type)
	{
	case sf::Event::KeyPressed:
	{
								  if (e.key.code == sf::Keyboard::Space)
								  {
									  m_end = true;
								  }
								  break;
	}
	default:
		break;
	}
}
